home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Views / ViewMap.cp < prev    next >
Text File  |  1997-06-28  |  5KB  |  281 lines

  1. // ViewMap.cp
  2.  
  3. #ifndef ViewMap_h
  4. #include "ViewMap.h"
  5. #endif
  6. #ifndef WindowObject_h
  7. #include "WindowObject.h"
  8. #endif
  9. #ifndef View_h
  10. #include "View.h"
  11. #endif
  12. #ifndef Pane_h
  13. #include "Pane.h"
  14. #endif
  15.  
  16. const ViewMap *ViewMap::current = 0;
  17.  
  18. ViewMap::ViewMap( const View& view )
  19.     : previous( current )
  20.   {
  21.     current = this;
  22.     
  23.     SetToVisible( view );
  24.     if ( visible )
  25.       {
  26.         clip -= Invalid( *window );
  27.         visible = !clip.IsEmpty();
  28.         visibleBounds = clip.Bounds();
  29.       }
  30.  
  31.     Reassert();
  32.   }
  33.  
  34. ViewMap::ViewMap( const View& view, IncludeInvalid )
  35.     : previous( current )
  36.   {
  37.     current = this;
  38.     SetToVisible( view );
  39.     Reassert();
  40.   }
  41.  
  42. ViewMap::ViewMap( const View& view, InvalidOnly )
  43.     : previous( current )
  44.   {
  45.     current = this;
  46.     
  47.     SetToVisible( view );
  48.     if ( visible )
  49.       {
  50.         clip &= Invalid( *window );
  51.         visible = !clip.IsEmpty();
  52.         visibleBounds = clip.Bounds();
  53.       }
  54.  
  55.     Reassert();
  56.   }
  57.  
  58. ViewMap::ViewMap( const ViewMap& source )
  59.   : window( source.window ),
  60.      bounds( source.bounds ),
  61.      clip( source.clip ),
  62.      visible( source.visible ),
  63.      previous( current )
  64.   {
  65.     current = this;
  66.     if ( previous != &source )
  67.         Reassert();
  68.   }
  69.  
  70. void ViewMap::SetToVisible( const View& view )
  71.   {
  72.     if ( view.Mapped() )
  73.       {
  74.         const Pane& pane( view.Owner() );
  75.         window = &pane.Window();
  76.         
  77.         if ( !Port().IsCurrent() )
  78.             Port().BeCurrent();
  79.  
  80.         bounds = pane.Bounds();
  81.         clip = window->VisibleRegion();
  82.         pane.Clip( clip );
  83.         visible = !clip.IsEmpty();
  84.         visibleBounds = clip.Bounds();
  85.       }
  86.      else
  87.       {
  88.         window = 0;
  89.         bounds = Rectangle::zero;
  90.         visible = false;
  91.       }
  92.   }
  93.  
  94. ViewMap::~ViewMap()
  95.   {
  96.     Assert( current == this );
  97.     
  98.     current = previous;
  99.     
  100.     if ( current != 0 )
  101.         current->Reassert();
  102.      else
  103.         ClipRect( &Rectangle::big );
  104.   }
  105.  
  106. RegionObject& ViewMap::Invalid( const WindowObject& window )
  107.   {
  108.     static RegionObject invalid;
  109.     invalid = window.InvalidRegion();
  110.     invalid += window.Port().GlobalToLocal();
  111.     return invalid;
  112.   }
  113.  
  114. GrafPortObject& ViewMap::Port() const
  115.   {
  116.     Assert( window != 0 );
  117.     return window->Port();
  118.   }
  119.  
  120. void ViewMap::operator=( const ViewMap& source )
  121.   {
  122.     window = source.window;
  123.     bounds = source.bounds;
  124.     clip = source.clip;
  125.     visible = source.visible;
  126.     visibleBounds = source.visibleBounds;
  127.  
  128.     if ( current == this )
  129.         Reassert();
  130.   }
  131.  
  132. void ViewMap::Set( const ViewMap& source, const Rectangle& restriction )
  133.   {
  134.     window = source.window;
  135.     bounds = restriction;
  136.     clip = source.clip;
  137.     clip &= restriction;
  138.     visible = source.visible && !clip.IsEmpty();
  139.     visibleBounds = clip.Bounds();
  140.     
  141.     if ( current == this )
  142.         Reassert();
  143.   }
  144.  
  145. void ViewMap::Reassert() const
  146.   {
  147.     Assert( current == this );
  148.     
  149.     if ( HasWindow() )
  150.       {
  151.         if ( !Port().IsCurrent() )
  152.             Port().BeCurrent();
  153.         
  154.         SetClip( clip );
  155.       }
  156.      else
  157.         ClipRect( &Rectangle::zero );
  158.   }
  159.  
  160. void ViewMap::RestrictTo( const Rectangle& restriction )
  161.   {
  162.     clip &= restriction;
  163.     visibleBounds = clip.Bounds();
  164.     
  165.     if ( clip.IsEmpty() )
  166.         visible = false;
  167.     
  168.     if ( current == this )
  169.         SetClip( clip );
  170.   }
  171.  
  172. void ViewMap::RestrictTo( const RegionObject& restriction )
  173.   {
  174.     clip &= restriction;
  175.     visibleBounds = clip.Bounds();
  176.     
  177.     if ( clip.IsEmpty() )
  178.         visible = false;
  179.  
  180.     if ( current == this )
  181.         SetClip( clip );
  182.   }
  183.  
  184. void ViewMap::Validate() const
  185.   {
  186.     Assert( current == this );
  187.     
  188.     if ( !Visible() )
  189.         return;
  190.     
  191.     ValidRgn( clip );
  192.   }
  193.  
  194. void ViewMap::Validate( const Rectangle& r ) const
  195.   {
  196.     Assert( current == this );
  197.     
  198.     if ( !Visible() )
  199.         return;
  200.     
  201.     RegionObject region( r );
  202.     region &= clip;
  203.     ValidRgn( region );
  204.   }
  205.  
  206. void ViewMap::Validate( const RegionObject& r ) const
  207.   {
  208.     Assert( current == this );
  209.     
  210.     if ( !Visible() )
  211.         return;
  212.     
  213.     RegionObject region( r );
  214.     region &= clip;
  215.     ValidRgn( region );
  216.   }
  217.  
  218. void ViewMap::Invalidate() const
  219.   {
  220.     Assert( current == this );
  221.     
  222.     if ( !Visible() )
  223.         return;
  224.  
  225.     InvalRgn( clip );
  226.   }
  227.  
  228. void ViewMap::Invalidate( const Rectangle& r ) const
  229.   {
  230.     Assert( current == this );
  231.     
  232.     if ( !Visible() )
  233.         return;
  234.     
  235.     RegionObject region( r );
  236.     region &= clip;
  237.     InvalRgn( region );
  238.   }
  239.  
  240. void ViewMap::Invalidate( const RegionObject& r ) const
  241.   {
  242.     Assert( current == this );
  243.     
  244.     if ( !Visible() )
  245.         return;
  246.     
  247.     RegionObject region( r );
  248.     region &= clip;
  249.     InvalRgn( region );
  250.   }
  251.  
  252. void ViewMap::Erase() const
  253.   {
  254.     Assert( current == this );
  255.     
  256.     if ( !Visible() )
  257.         return;
  258.     
  259.     EraseRect( &bounds );
  260.   }
  261.  
  262. void ViewMap::Erase( const Rectangle& r ) const
  263.   {
  264.     Assert( current == this );
  265.     
  266.     if ( !Visible() )
  267.         return;
  268.     
  269.     EraseRect( &r );
  270.   }
  271.  
  272. void ViewMap::Erase( const RegionObject& r ) const
  273.   {
  274.     Assert( current == this );
  275.     
  276.     if ( !Visible() )
  277.         return;
  278.     
  279.     EraseRgn( r );
  280.   }
  281.